package com.qezhhnjy.mall.order.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.order.OrderItem;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.order.service.OrderItemService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 订单项信息 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "订单项信息接口")
@Slf4j
@RequestMapping("/order-item")
public class OrderItemController {
    @Resource
    private OrderItemService orderItemService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取订单项信息信息")
    public BaseResult<OrderItem> get(Long id) {
        OrderItem orderItem = orderItemService.getById(id);
        return BaseResult.success(orderItem);
    }

    @PostMapping("/save")
    @Operation(summary = "新增订单项信息信息")
    public BaseResult<OrderItem> save(@RequestBody OrderItem orderItem) {
        orderItemService.save(orderItem);
        return BaseResult.success(orderItem);
    }

    @PutMapping("/update")
    @Operation(summary = "更新订单项信息信息")
    public BaseResult<OrderItem> update(@RequestBody OrderItem orderItem) {
        orderItemService.updateById(orderItem);
        return BaseResult.success(orderItem);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取订单项信息信息")
    public BaseResult<Page<OrderItem>> page(@RequestBody Page<OrderItem> page) {
        orderItemService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除订单项信息信息")
    public BaseResult<Long> delete(Long id) {
        orderItemService.removeById(id);
        return BaseResult.success(id);
    }
}

